<?php

/**
 * Description of User
 *
 * @author Tommy Vercety
 */
class Users {

    private $_db,
            $_results;

    public function __construct() {
        $this->_db = DB::getInstance();
    }

    public function login($username, $password) {
        if ($this->_db->get(Config::get('db_tables/users'), array('username', '=', $username))->count() && 
            $this->_db->get(Config::get('db_tables/users'), array('password', '=', Hash::make($password)))->count()) {
            return TRUE;
        }
        else {
            return FALSE;
        }
    }
    
    public function isAdmin($user) {
        if ($this->_db->query('SELECT * FROM ' . Config::get('db_tables/users') . ' WHERE username = "' . $user . '" AND admin = 1')->count()) {
            return TRUE;
        }
    }

    public function getUserID($user) {
         if ($this->_results = $this->_db->get(Config::get('db_tables/users'), array('username', '=', $user))->first()) {
            return $this->_results;
        }
    }

}
